package com.zhima.controller.feign;

import cn.hutool.core.bean.BeanUtil;
import com.zhima.dto.AiGuide;
import com.zhima.dto.FeignJudgeRecordDTO;
import com.zhima.dto.FeignJudgeResult;
import com.zhima.enums.JudgeState;
import com.zhima.service.OjJudgeRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author : Administer
 * @date : 2023-09-06 09:21
 **/
@RestController
@RequestMapping("/judge-record/feign")
public class OjJudgeRecordFeignController {
    @Autowired
    private OjJudgeRecordService ojJudgeRecordService;

    /**
     * 更新测评记录的测评状态
     *
     * @param judgeRecordId
     * @param judgeRecordState
     */
    @PostMapping("/{judgeRecordId}/{judgeRecordState}")
    public boolean updateJudgeRecordState(@PathVariable("judgeRecordId") Long judgeRecordId, @PathVariable("judgeRecordState") String judgeRecordState) {
        return ojJudgeRecordService.updateJudgeRecordState(judgeRecordId, JudgeState.valueOf(judgeRecordState));
    }

    /**
     * 根据{judgeRecordId}获取测评记录信息
     *
     * @param judgeRecordId
     * @return
     */
    @GetMapping("/{judgeRecordId}")
    public FeignJudgeRecordDTO queryJudgeRecordById(@PathVariable("judgeRecordId") Long judgeRecordId) {
        return BeanUtil.copyProperties(ojJudgeRecordService.queryJudgeRecordById(judgeRecordId), FeignJudgeRecordDTO.class);
    }

    /**
     * 提供给judger测评机更新测评结果的接口
     *
     * @param judgeRecordId
     * @param feignJudgeResult
     * @return
     */
    @PostMapping("/judge0/notify/{judgeRecordId}")
    public boolean updateJudge0Result(@PathVariable("judgeRecordId") Long judgeRecordId, @RequestBody FeignJudgeResult feignJudgeResult) {
        return ojJudgeRecordService.updateJudge0Result(judgeRecordId, feignJudgeResult);
    }

    /**
     * 删除所有与questionId关联的测评记录
     *
     * @param questionId
     * @return
     */
    @DeleteMapping("/{questionId}")
    public boolean deleteQuestionJudgeRecord(@PathVariable("questionId") Long questionId) {
        return ojJudgeRecordService.deleteQuestionJudgeRecord(questionId);
    }

    @PostMapping("/ai")
    public boolean aiGuide(@RequestBody AiGuide aiGuide) {
        return ojJudgeRecordService.updateAiGuide(aiGuide);
    }
}
